home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Compute! Gazette 1986 October
/
1986-10.d64
/
simple assembler
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-09-20
|
4KB
|
139 lines
10 h=0:rem if h = 0 then assembly is in decimal
50 he$="0123456789abcdef":sz=1:zo$="000"
100 print"[147] simple assembler conventions:"
110 dimm$(56),ty(56),op(56)
120 fori=1to56:readm$(i)
122 rop$=mid$(m$(i),4,1):ty(i)=val(rop$)
124 op$=right$(m$(i),3):op(i)=val(op$)
126 m$(i)=left$(m$(i),3)
140 nexti: print
150 print"immediate lda #15
155 [153]"absolute lda 1500
160 print"zero page lda 15
165 [153]"accumulator asl
170 print"indirect x lda (15x)
175 [153]"indirect y lda (15)y
177 print"zero page x lda 15x
179 [153]"zero page y ldx 15y
180 print"absolute x lda 1500x
185 [153]"absolute y lda 1500y
189 print:print" enter all numbers in ";
190 ifh=1 thenprint"hex":goto200
195 print"decimal"
200 print:print"please input starting address for ml program":input sa$
210 ifh=1thenh$=sa$:gosub5000:sa=de:goto220
215 sa=val(sa$)
220 ta=sa:print"[147]":rem clear the screen
230 ifh=1thende=sa:sz=3:gosub4000:printh$;:goto240
235 printsa" ";
240 inputmn$:print"[145]"spc(20);:rem go up one line and over 20 spaces
241 rem add new pseudo-ops here
242 ifright$(mn$,7)="forward"thenfb=sa
243 ifright$(mn$,7)="resolve"thenfr=sa-fb:pokefb+1,fr-2:print" ok":goto230
244 ifright$(mn$,4)="poke"thenprint"addr,number(dec)";
245 ifright$(mn$,4)="poke"theninputadr,num:pokeadr,num:goto230
250 ifmn$="end"thenprint:print" program is from"ta"to"sa:end
260 l=len(mn$):l$=left$(mn$,3)
270 fori=1to56:ifl$=m$(i)then300
280 nexti
290 goto850
300 rem primary opcode categories
301 ty=ty(i):op=op(i)
305 iffb=sathentn=0:goto2010
310 ifty=0thengoto1000
320 ifty=3thenty=1:ifl=3thenop=op+8:goto1000
330 r$=right$(mn$,l-4):ifh=1thengosub6000
340 lr$=left$(r$,1):ll=len(r$):iflr$="#"then480
350 iflr$="("then520
360 ifty=8then600
370 ifty=3thenop=op+8:goto1000
380 ifright$(r$,1)="x"orright$(r$,1)="y"then630
390 ifleft$(l$,1)="j"then820
400 tn=val(r$):iftn>255then430
410 ifty=1orty=3orty=4orty=5thenop=op+4
420 goto2000
430 h%=tn/256:l%=tn-256*h%:ifty=2orty=7thenop=op+8:goto470
440 ifty=1orty=3orty=4orty=5thenop=op+12:goto470
450 ifty=6orty=9then470
460 goto850
470 goto3000
480 tn=val(right$(r$,ll-1))
490 ifty=1thenop=op+8:goto2000
500 ifty=4orty=5thengoto2000
510 goto850
520 ifright$(r$,2)=")y"then540
530 ifright$(r$,2)="x)"then570
540 tn=val(mid$(r$,2,ll-3))
550 ifty=1thenop=op+16:goto2000
560 goto850
570 tn=val(mid$(r$,2,ll-3))
580 ifty=1thengoto2000
590 goto850
600 tn=val(r$):tn=tn-sa-2:iftn<-128ortn>127thenprint"too far ";:goto850
610 iftn<0thentn=tn+256
620 goto2000
630 ifright$(r$,2)=")y"then540
640 ifright$(r$,1)="x"then720
650 rem *zero y
660 tn=val(left$(r$,ll-1)):iftn>255then680
670 ifty=2orty=5then730
675 ifty=1then760
680 gosub770:ifty=1thenop=op+24:goto710
690 ifty=5thenop=op+28:goto710
700 goto850
710 goto3000
720 tn=val(left$(r$,ll-1)):iftn>255thengosub770:goto780
730 ifty=2thenop=op+16:goto760
740 ifty=1orty=3orty=5thenop=op+20:goto760
750 goto850
760 goto2000
770 h%=tn/256:l%=tn-256*h%:return
780 ifty=2thenop=op+24:goto810
790 ifty=1orty=3orty=5thenop=op+28:goto810
800 goto850
810 goto3000
820 tn=val(r$)
830 gosub770
840 goto710
850 print" error ":goto230
1000 rem 1 byte instructions
1010 pokesa,op:sa=sa+1:ifh=1then 1030
1020 printop:goto230
1030 de = op:gosub4000:printh$:goto230
2000 rem 2 byte instructions
2005 iftn>255thenprint" incorrect argument.":goto230
2010 pokesa,op:pokesa+1,tn:sa=sa+2:ifh=1then2030
2020 printop;tn:goto230
2030 de = op:gosub4000:printh$" ";
2040 de = tn:gosub4000:printh$:goto230
3000 rem 3 byte instructions
3010 pokesa,op:pokesa+1,l%:pokesa+2,h%:sa=sa+3:ifh=1then3030
3020 printop;l%;h%:goto230
3030 de = op:gosub4000:printh$" ";
3040 de = l%:gosub4000:printh$" ";
3050 de = h%:gosub4000:printh$:goto230
4000 rem decimal to hex (de to h$)
4010 h$="":form=szto0step-1:n%=de/(16^m):de=de-n%*16^m:h$=h$+mid$(he$,n%+1,1)
4020 next:sz=1:return
5000 rem hex to decimal (h$ to de)
5010 d=0:q=3:form=1to4:forw=0to15:ifmid$(h$,m,1)=mid$(he$,w+1,1)then5030
5020 nextw
5030 d1=w*(16^(q)):d=d+d1:q=q-1:nextm:de=int(d):return
6000 rem accept hex opcode input and translate it to decimal
6010 ifleft$(r$,1)="#"thenh$="00"+right$(r$,2):gosub5000:r$="#"+str$(de):return
6020 ls=len(r$):az$=left$(r$,1):za$=mid$(r$,ls,1):ifaz$<>"("then6050
6030 ifza$="y"thenh$="00"+mid$(r$,2,2):gosub5000:r$="("+str$(de)+")y":return
6040 ifza$=")"thenh$="00"+mid$(r$,2,2):gosub5000:r$="("+str$(de)+"x)":return
6050 ifza$="x"orza$="y"then6070
6060 h$=left$(zo$,4-ls)+r$:gosub5000:r$=str$(de):return
6070 ifls=5thenh$=left$(r$,4):goto6090
6080 h$="00"+left$(r$,2)
6090 gosub5000:r$=str$(de)+za$:return
20000 dataadc1097,and1033,asl3002,bcc8144,bcs8176,beq8240,bit7036,bmi8048
20010 databne8208,bpl8016,brk0000,bvc8080,bvs8112,clc0024,cld0216,cli0088
20020 dataclv0184,cmp1193,cpx4224,cpy4192,dec2198,dex0202,dey0136,eor1065
20030 datainc2230,inx0232,iny0200,jmp6076,jsr9032,lda1161,ldx5162,ldy5160
20040 datalsr3066,nop0234,ora1001,pha0072,php0008,pla0104,plp0040,rol3034
20050 dataror3098,rti0064,rts0096,sbc1225,sec0056,sed0248,sei0120,sta1129
20060 datastx2134,sty2132,tax0170,tay0168,tsx0186,txa0138,txs0154,tya0152